package com.ktian.android.compression.image;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

import android.util.Log;

public class MyInputStream extends FilterInputStream{
    int sum;

    public MyInputStream(InputStream in) {
        super(in);
    }

    
    public int read(byte[] buffer, int offset, int length) {
        int len = -1;
        try {
           len = super.read(buffer, offset, length);
           sum += len;
           return len;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        throw new RuntimeException();
    }
    
    public int getTotalLength() {
        Log.d("get photo size:", "尺寸:" + sum);
        return sum;
    }
    
    @Override
    public long skip(long n) throws IOException {
        long totalBytesSkipped = 0L;
        while (totalBytesSkipped < n) {
            long bytesSkipped = in.skip(n - totalBytesSkipped);
            if (bytesSkipped == 0L) {
                  int b = read();
                  if (b < 0) {
                      break;  // we reached EOF
                  } else {
                      bytesSkipped = 1; // we read one byte
                  }
           }
            totalBytesSkipped += bytesSkipped;
        }
        return totalBytesSkipped;
    }
}
